package com.yun.platform.config.handler;

import com.yun.platform.config.dto.RData;
import com.yun.platform.excption.BizException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * laich  Date:2021/9/11
 * 异常处理器
 * @Desciprtion:  自定义全局异常处理器
 */

@Slf4j
@RestControllerAdvice
public class YunHandlerException{

    @ExceptionHandler(BizException.class)
    public RData handleValidationBizException(HttpServletRequest request, BizException e) {
        return RData.fail(e.getMessage());
    }

    /**
     * 主动throw的异常
     *
     * @param e
     * @param response
     * @return
     */
    @ExceptionHandler(Exception.class)
    public RData handleException(Exception e, HttpServletResponse response) {

        log.error(" 严重错误 ---Exception:",e);
        return RData.fail("未知参数错误!");
    }

}
